package xio.ccf_201312;

import java.util.Scanner;
/**
 * 201312-1 出现次数最多的数 100分
 * Created by Xio on 2017/11/8 0006.
 */
public class MajorCounting {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[10001]; //输入的最大值为10000
		for (int i = 0; i < n; i++) {
			arr[sc.nextInt()]++;
		}

		int curMax = 0;  //当前出现的最多次数
		int result = 1;
		for (int i = 0; i < arr.length; i++) {
			int a = arr[i];
			if (a == 0) {
				continue;
			}
			if (a > curMax) {
				curMax = a;
				result = i;
			} else if (a == curMax) {
				result = result > i ? i : result;
			}
		}
		System.out.println(result);
	}
}
